////
////  NetworkManage.swift
////  ptbuy
////
////  Created by MyMac on 2024/12/2.
////
//
//import Foundation
//import SwiftUI
//import UIKit
//struct NetworkManage{
//    
//    @Binding var isLoading:Bool
//    @Binding var showingUpdateSheet:Bool
//    @Binding var downurl:String
//    @Binding var description:String
//    
//    // 发送 GET 请求的函数
//    func appUpdateFunc() async{
//        
//        downurl = ""
//        description = ""
//        
//        // 设置请求的 URL
//        guard let url = URL(string: "http://www.pengtushuzhi.com/api/app/latest?type=cwty") else {
////            print("Invalid URL")
//            isLoading = false
//            return
//        }
//        
//        // 创建 URLSession 数据任务
//        let task = URLSession.shared.dataTask(with: url) { (data, response, error) in
//            if let error = error {
////                print("Error occurred: \(error.localizedDescription)")
//                isLoading = false
//                return
//            }
//            
//            // 确保响应有效并且数据非空
//            if let data = data {
//                // 尝试解析 JSON 数据
//                do {
//                    let json = try JSONSerialization.jsonObject(with: data, options: [])
////                    print("Response: \(json)")
//                    
//                    do {
//                        let posts = try JSONDecoder().decode(ResultApi.self, from: data)
//                    
////                        print("Post \(posts.success): \(posts.message): \(posts.data): \(posts.data.description): \(posts.data.version): \(posts.data.downurl): \(posts.data.date)")
//                        isLoading = false
//                      let appversion =  Utils.appVersion()
//                        print("当前版本：\(appversion)")
//                        print("最新版本：\(posts.data.version)")
//                        
//                        // 判断大小
//                       if let newVersion = Double(posts.data.version.lowercased()), let localVersion = Double(appversion.lowercased()) {
//                           if newVersion > localVersion {
//                               downurl = posts.data.downurl
//                               description = posts.data.description
//                               
//                               showingUpdateSheet = true
//                           }
//                       }else{
//                           downurl = "isEmpty"
//                       }
//                  
//                       } catch {
////                           print("Error decoding JSON: \(error.localizedDescription)")
//                           isLoading = false
//                       }
//                  
//                } catch {
//                    isLoading = false
////                    print("Error parsing JSON: \(error.localizedDescription)")
//                }
//            }
//        }
//        
//        // 启动任务
//        task.resume()
//    }
//}
